package com.mystudy.leetcode.problem.tree.p_669;

import com.mystudy.leetcode.base.TreeNode;

/**
 * @program: infoalgorithm
 * @description: 修剪二叉搜索树
 * @author: zhouzhilong
 * @create: 2019-07-24 13:49
 **/
public class Solution {


    public TreeNode trimBST(TreeNode root, int L, int R) {
        if (root == null) {
            return null;
        }

        if (root.val < L) {
            return trimBST(root.right, L, R);
        } else if (root.val > R) {
            return trimBST(root.left,L,R);
        }else{
            root.right = trimBST(root.right,L,R);
            root.left = trimBST(root.left,L,R);
            return root;
        }

    }
}
